package com.applink.sell_proof.model;

import java.util.ArrayList;

import com.applink.sell_proof.pojo.GenericAttribute;
import com.applink.sell_proof.share.Parameter;
import com.applink.sell_proof.utilXMLParser.ObjPropInfo;

public class NewRewardProject {
	private String ProgramID;
	private String ProgramName;
	private String Quarter;
	private String Year;
	private String ProgramCode;
	private String TotalRewardAmount;
	private String RewardType;
	private String Name;
	private String ObjectID;
	private String TotalAmount;
	private String Period;
	public String getProgramID() {
		return ProgramID;
	}
	public void setProgramID(String programID) {
		ProgramID = programID;
	}
	public String getProgramName() {
		return ProgramName;
	}
	public void setProgramName(String programName) {
		ProgramName = programName;
	}
	public String getQuarter() {
		return Quarter;
	}
	public void setQuarter(String quarter) {
		Quarter = quarter;
	}
	public String getYear() {
		return Year;
	}
	public void setYear(String year) {
		Year = year;
	}
	public String getProgramCode() {
		return ProgramCode;
	}
	public void setProgramCode(String programCode) {
		ProgramCode = programCode;
	}
	public String getTotalRewardAmount() {
		return TotalRewardAmount;
	}
	public void setTotalRewardAmount(String totalRewardAmount) {
		TotalRewardAmount = totalRewardAmount;
	}
	public String getRewardType() {
		return RewardType;
	}
	public void setRewardType(String rewardType) {
		RewardType = rewardType;
	}
	public String getName() {
		return Name;
	}
	public void setName(String name) {
		Name = name;
	}
	public String getObjectID() {
		return ObjectID;
	}
	public void setObjectID(String objectID) {
		ObjectID = objectID;
	}
	public String getTotalAmount() {
		return TotalAmount;
	}
	public void setTotalAmount(String totalAmount) {
		TotalAmount = totalAmount;
	}
	public void setPeriod(String period) {
		Period = period;
	}
	public String getPeriod() {
		return Period;
	}
	
	@SuppressWarnings("rawtypes")
	public ArrayList<GenericAttribute> convertIntoGenericAttributes(ArrayList<ObjPropInfo> objPropList){
		
		ArrayList<GenericAttribute> attributeList = new ArrayList<GenericAttribute>();
		
		for(int i=0; i< objPropList.size();i++){
			ObjPropInfo objPropInfo = objPropList.get(i);
    		
    		String name = objPropInfo.getOPID();
    		String dataType = objPropInfo.getDataType();
    		
    		String value = this.getValueByName(name);
    		
    		if(value == ""){
    			value = "0";
    		}
    		if(dataType.compareTo(Parameter.TYPE_INT) == 0) {
    			GenericAttribute<String, Integer> attribute = new GenericAttribute<String, Integer>(name, (int) Long.parseLong(value));
    			attributeList.add(attribute);
    		} else if (dataType.compareTo(Parameter.TYPE_CHAR) == 0){
    			GenericAttribute<String, String> attribute = new GenericAttribute<String, String>(name, String.valueOf(value));
    			attributeList.add(attribute);
    		} else if (dataType.compareTo(Parameter.TYPE_DOUBLE) == 0){
    			GenericAttribute<String, Double> attribute = new GenericAttribute<String, Double>(name, Double.parseDouble(value));           			
    			attributeList.add(attribute);
    		}
    	
		}
		
		return  attributeList;
	}
	
	public String getValueByName(String name){
		
		String value="";
		Object instance;
		try {
			instance = getClass().getDeclaredField(name).get(this);
			value = instance.toString();
		} catch (Exception e) {
			value = "";
		}
		return value;
	}
}
